#/bin/bash

while getopts f: flag
do
  case "${flag}" in
    f) filename=${OPTARG};;
    *) echo "Incorrect options passed " && exit 1
  esac
done

echo -n Check filename parametes ...
if [[ -z $filename ]]; then
  echo " Fail  File name was not defined"
  exit 1
fi
echo OK

echo -n Check filename  ...
if [[ ! -f $filename ]]; then
  echo " Fail  File was not found"
  exit 1
fi
echo OK

file_extension="${filename##*.}"
file_basename=${filename%.*}
timestamp=$(date +'%Y-%m-%d-%H-%M-%S')
updated_name="$file_basename-$timestamp.$file_extension"
echo "Name will be : " "$updated_name"
echo "Renaming ..."
mv "$filename" "$updated_name"
echo -n "Check renamed file ... "
if [[ -f "$updated_name" ]]; then
   echo " OK"
else
  echo " Hmm ... could not move $filename to $updated_name"
fi